package xyz.zdsoft.homework_manage_module.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xyz.zdsoft.common.utils.Result;
import xyz.zdsoft.homework_manage_module.bo.QueryJob;
import xyz.zdsoft.homework_manage_module.vo.RestGroup;
import xyz.zdsoft.homework_manage_module.vo.RestQueryJob;
import xyz.zdsoft.homework_manage_module.vo.RestStudent;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface TeacherTaskMapper {
   List<RestQueryJob> NewQueryJob(QueryJob queryJob,String teacherName);
   @Select("SELECT su.`name` FROM work_info wi LEFT JOIN work_submit_info wsi ON wi.id =wsi.work_id \n" +
           "LEFT JOIN sys_user su on wsi.student_id=su.id WHERE wi.id=#{id} AND wi.del_flag='0' AND wsi.del_flag='0' \n" +
           "AND su.del_flag='0'")
   List<String> NewQueryStuName(@Param("id") Integer id);
   @Select("SELECT team_name FROM wrok_team_view WHERE id=#{id}")
   String NewQueryTeamName(@Param("id") Integer id);

   @Update("UPDATE work_info SET del_flag='1' WHERE id=#{id}")
   boolean DeleteJob(@Param("id") Integer id);

   @Select("SELECT DISTINCT ci.id,ci.course_name FROM course_info ci\n" +
           "LEFT JOIN course_project_info cpi on ci.id=cpi.course_info_id\n" +
           "LEFT JOIN course_project_teacher_info cti on cpi.id=cti.course_project_info_id WHERE cti.teacher_id=#{teacherId}")
    List<HashMap<String,Object>> SelectCourse(@Param("teacherId") Integer teacherId);

   @Select("SELECT  ci.id,cpi.responsible_teacher_id FROM course_info ci\n" +
           "LEFT JOIN course_project_info cpi on ci.id=cpi.course_info_id \n" +
           "WHERE ci.id=#{id} AND cpi.responsible_teacher_id=#{teacherId}")
   List<HashMap<String,Object>> JobType(@Param("id") Integer id,@Param("teacherId") Integer teacherId);
   @Select("SELECT DISTINCT ti.team_name,ti.id FROM course_info ci\n" +
           "LEFT JOIN course_project_info cpi on ci.id=cpi.course_info_id \n" +
           "LEFT JOIN course_student cs on cs.course_project_info_id=cpi.id\n" +
           "LEFT JOIN team_member_info tmi on tmi.student_id=cs.student_id\n" +
           "LEFT JOIN team_info  ti on ti.id= tmi.team_info_id\n" +
           "WHERE ci.id=#{id}  AND ti.id IS not NULL")
   List<RestGroup> RestGroup(@Param("id") Integer id);
  @Select("SELECT cs.student_id as student_id, su.`name`  AS student_name FROM course_info ci\n" +
         "LEFT JOIN course_project_info cpi on ci.id=cpi.course_info_id \n" +
         "LEFT JOIN course_student cs on cs.course_project_info_id=cpi.id\n" +
         "LEFT JOIN team_member_info tmi on tmi.student_id=cs.student_id\n" +
         "LEFT JOIN team_info  ti on ti.id= tmi.team_info_id\n" +
         "LEFT JOIN sys_user su on su.id = cs.student_id\n" +
         "WHERE ci.id=#{id}  AND ti.id IS not NULL AND ti.id=#{teamId}")
   List<RestStudent> SelectStudents(@Param("id") Integer id,@Param("teamId") Integer teamId);

}
